<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>清除定时器</title>
</head>
<body>
    <button class="begin">开始</button>
    <button class="stop">停止</button>
    <script>
        var begin = document.querySelector('.begin')
        var stop = document.querySelector('.stop')
        var times = null
        begin.addEventListener('click',function(){
            times = setInterval(function() {
                console.log('123');
            },10)
        })
        stop.addEventListener('click',function(){
            clearTimeout(times)
        })
    </script>
</body>
</html>